﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using cecbData;
using cecbClasses;
using cecbClasses.Data_Classes;
using System.Text.RegularExpressions;
using cecbClasses.Data_Adapters;
using cecbClasses.Data_Adapters.Project;


namespace CECB.Project
{
    /// <summary>
    /// Interaction logic for PrjctType_ParamDetails.xaml
    /// </summary>
    public partial class PrjctType_ParamDetails : Window
    {
        Func_Projects ObjProjcts;
        Data_PTypeMainParam objMparam = new Data_PTypeMainParam();
        List<ProjTyMParams> lstProjTypeMParams;
        List<ProjTySubParams> sParamList;

        public PrjctType_ParamDetails()
        {
            InitializeComponent();
            ObjProjcts = new Func_Projects();
            lstProjTypeMParams = new List<ProjTyMParams>();
            
        }

        //load all main parameters to project type
        public void GetMainParameters()
        {
            lstProjTypeMParams = ObjProjcts.getAllMainParamerter();

            FillMainParameters();
        }


        //diplay on list box
        public void FillMainParameters()
        {
           // listBox_ShwMainParm.Items.Clear();

            foreach (ProjTyMParams mParam in lstProjTypeMParams)
            {
                //listBox_ShwMainParm.Items.Add(mParam);
            }
        }

        

        public void GetSubParameters()
        {
            if (comboBox_SelectMainParam.SelectedIndex > -1)
            {
                sParamList = ObjProjcts.getAllSubParamerter(comboBox_SelectMainParam.SelectedValue.ToString());
            }
            else {
                MessageBox.Show("Select a sub parameter", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            FillSubParameters();
        }
        


        //display sub paramters on list box
        public void FillSubParameters()
        {
            listBox_ShwSubParam.Items.Clear();

            foreach (ProjTySubParams subParam in sParamList)
            {
                listBox_ShwSubParam.Items.Add(subParam);
            }
        }

       //load to project type main paramtrs to  combo box

        public void FillPrjTypeMainParam()
        {

            comboBox_SelectMainParam.ItemsSource = lstProjTypeMParams;

        }

        //load project types to combo box
        public void FillPrjType()
        {

            List<cecbData.ProjectTypes> ProjectTypeList = ObjProjcts.GetAllProjectTypes();
            comboBox_projType.ItemsSource = ProjectTypeList;

        }
        //events

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }


        private void comboBox_projType_DropDownOpened(object sender, EventArgs e)
        {
            
        }
        
        private void comboBox_projType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GetMainParameters();

        }

        
        private void comboBox_SelectMainParam_DropDownOpened(object sender, EventArgs e)
        {
            comboBox_SelectMainParam.ItemsSource = lstProjTypeMParams;//mtnta data sorce dnna onne :D


        }

        private void comboBox_SelectMainParam_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GetSubParameters();
        }

        //private void listBox_ShwMainParm_KeyUp(object sender, KeyEventArgs e)
        //{
        //    if ((e.Key == Key.Delete) && (listBox_ShwMainParm.SelectedIndex > -1))
        //    {
        //        int SelIndex;
        //        SelIndex = listBox_ShwMainParm.SelectedIndex;

        //        lstProjTypeMParams.RemoveAt(SelIndex);
        //        //listBox_ShwMainParm.Items.RemoveAt(SelIndex);
        //    }
        //}

        private void button_AddNewMParam_Click(object sender, RoutedEventArgs e)
        {
            if (textBox_NewMainParam.Text != "")
            {
                ObjProjcts = new Func_Projects();

                ObjProjcts.insertIntoMainParam(textBox_NewMainParam.Text, comboBox_projType.SelectedValue.ToString());
                GetMainParameters();


                textBox_NewMainParam.Text = "";
                //Data_PTypeMainParam clsPtypMainParm = new Data_PTypeMainParam();
                //clsPtypMainParm.Pmparam_Name = textBox_NewMainParam.Text.ToString();

                //lstProjTypeMParams.Add(clsPtypMainParm);
                //listBox_ShwMainParm.Items.Add(clsPtypMainParm);

            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            FillPrjType();

        }

        private void listBox_ShwSubParam_KeyUp(object sender, KeyEventArgs e)
        {
            if ((e.Key == Key.Delete) && (listBox_ShwSubParam.SelectedIndex > -1))
            {
                int SelIndex;
                SelIndex = listBox_ShwSubParam.SelectedIndex;

                sParamList.RemoveAt(SelIndex);
                listBox_ShwSubParam.Items.RemoveAt(SelIndex);
            }
        }

        private void button_InsertPrjTypPrm_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void button_AddNewSbparam_Click(object sender, RoutedEventArgs e)
        {
            if (textBox_NewSubParam.Text != "")
            {
                ObjProjcts = new Func_Projects();

                ObjProjcts.insertIntoSubPrm(textBox_NewSubParam.Text, comboBox_SelectMainParam.SelectedValue.ToString());
                //GetMainParameters();
                GetSubParameters();

                textBox_NewSubParam.Text = "";
            }
        }
    }
}
